package com.winz.cultureapp.activity;

import android.content.Intent;
import android.text.Html;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.winz.cultureapp.R;
import com.winz.cultureapp.base.BaseAppCompatActivity;
import com.winz.cultureapp.constants.Constants;
import com.winz.cultureapp.entity.ArtListBean;
import com.winz.cultureapp.entity.CultureDesBean;
import com.winz.cultureapp.http.OnResponeListener;
import com.winz.cultureapp.http.request.RequestFactory;
import com.winz.cultureapp.http.util.HttpUitls;
import com.winz.cultureapp.utils.JsonUtil;
import com.winz.cultureapp.utils.Logger;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 艺术品详情
 */
public class ArtDesActivity extends BaseAppCompatActivity {

    @BindView(R.id.tv_top_title)
    TextView mTv_top_title;
    @BindView(R.id.tv_content)
    TextView mTv_content;
    @BindView(R.id.iv_pic)
    ImageView mIv_pic;
    private String desId;

    @Override
    protected int contentView() {
        return R.layout.activity_art_des;
    }

    @Override
    protected void initViews() {
        setStatusBar(getResources().getColor(R.color.base_color));
        mTv_top_title.setText(getString(R.string.act_des_top_title));
    }

    @Override
    protected void loadDatas(Intent intent) {
        if (intent != null){
            if (intent.getExtras() != null){
                desId = intent.getExtras().getString(Constants.KEY.ART.ITEM_DES_ID);
                if (TextUtils.isEmpty(desId)){
                    showMsg("文物详情ID不存在");
                }else {
                    getDes();
                }
            }
        }
    }

    private void getDes() {
        showProgressDialog();

        HttpUitls.onGet("cultural_detail", desId, new OnResponeListener<CultureDesBean>() {
            @Override
            public void onSuccess(CultureDesBean bean) {
                Logger.d("cultural_detail==>>", JsonUtil.getJsonFromObj(bean));
                if (bean.code == 0) {
//                    mTv_content.setText(bean.data.content);
                    mTv_content.setText(Html.fromHtml(bean.data.content));
                    Glide.with(context)
                            .load(bean.data.imageUrl)
                            .error(R.drawable.pic_default)
                            .into(mIv_pic);
                } else {
                    showMsg(bean.msg);
                }
                dismissProgressDialog();
            }

            @Override
            public void onFailed(String error) {
                Logger.d("cultural_detail==>>", error);
                dismissProgressDialog();
                showMsg(error);

            }
        });
    }

    @OnClick(R.id.fl_back)
    public void onClick() {
        finish();
    }
}
